package com.lepu.app.fun.hospital;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.utils.AppEnterTongJi;
import com.app.utils.Const;
import com.app.utils.LoginUtil;
import com.core.lib.application.BaseFragmentActivity;
import com.core.lib.utils.main.UIHelper;
import com.eyzhs.app.R;
import com.lepu.app.fun.chat.activity.OnlineActivity;
import com.lepu.app.fun.chat.business.uiflow.UITransition;
import com.lepu.app.fun.hospital.bean.HospitalDoctor;
import com.lepu.app.widget.CustomTopBarNew;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewLeftLayoutListener;

public class HospitalDoctordetailActivity extends BaseFragmentActivity
		implements OnTopbarNewLeftLayoutListener {

	HospitalDoctor mDoctor = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hospital_doctor_detail_activity);

		init();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	/**
	 * 添加页面动画，需要重写这个方法，
	 */
	@Override
	public void onBackPressed() {
		finish(true);
	}

	/**
	 * 初始化方法
	 */
	private void init() {
		// topbar
		CustomTopBarNew topbar = (CustomTopBarNew) findViewById(R.id.topbar);
		topbar.setTopbarTitle("医生简介");
		topbar.setonTopbarNewLeftLayoutListener(this);

		if (getIntent() != null && getIntent().getExtras() != null) {
			mDoctor = (HospitalDoctor) getIntent().getSerializableExtra(
					Const.DOCTOR);

			if(mDoctor == null)
			{
				return;
			}

			TextView txt_user_name = (TextView) findViewById(R.id.txt_user_name);
			TextView txt_teachtitle = (TextView) findViewById(R.id.txt_teachtitle);
			TextView txt_hospital = (TextView) findViewById(R.id.txt_hospital);
			TextView txt_goodat = (TextView) findViewById(R.id.txt_goodat);
			TextView txt_resume = (TextView) findViewById(R.id.txt_resume);
			ImageView ic_img = (ImageView) findViewById(R.id.ic_img);
			txt_user_name.setText(mDoctor.DoctorName);
			txt_teachtitle.setText(mDoctor.JobTitle);
			txt_hospital.setText(mDoctor.HospitalName);
			txt_goodat.setText(mDoctor.Skill);
			txt_resume.setText(mDoctor.Resume);

//			UniversalImageLoadTool.disPlay(mDoctor.Avatar, ic_img,
//					R.drawable.app_ic_default_avatar);
			LoginUtil.loadSelfUserImage(this, ic_img, mDoctor.Avatar);

			TextView newPriceTextView = (TextView) findViewById(R.id.newPriceTextView);
			TextView oldPriceTextView = (TextView) findViewById(R.id.oldPriceTextView);

			oldPriceTextView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);

			newPriceTextView.setText(String
					.format("%d金币/次", mDoctor.ConsultCredits));
			oldPriceTextView.setText(String.format("原价：%.0f金币/次",
					mDoctor.MarketConsultCredits));
			
			Button chatButton = (Button) findViewById(R.id.chatButton);
			if (mDoctor.IsOnDuty == 1) {
				
			} else {
				chatButton.setBackgroundColor(Color.parseColor("#bbbbbb"));
			}
			
			AppEnterTongJi.clickEvent(58, mDoctor.DoctorID);
		}
	}

	@Override
	public void onTopbarLeftLayoutSelected() {
		finish(true);
	}

	public void viewClick(View view) {
		int rid = view.getId();
		switch (rid) {
		case R.id.chatButton:

			if (mDoctor.IsOnDuty == 1) {
				sendMesage();
			} else {
				UIHelper.showToast(this, "该医生当前不在线，请选择其他医生咨询");
			}
			break;

		default:
			break;
		}
	}

	private void sendMesage() {

		boolean flag = LoginUtil.jumpLogin(this);
		if (flag) {
			return;
		}

		Intent intent = new Intent(this, OnlineActivity.class);
		intent.putExtra("doctorEntity", mDoctor);
		intent.putExtra("ConsultPrice", mDoctor.ConsultCredits);
		startActivity(intent);
		UITransition.setActivityStartRightIn(this);

	}

}
